package com.bawei.erp.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bawei.erp.mapper.POrderMapper;
import com.bawei.erp.model.POrder;
import com.bawei.erp.model.Stock;
import com.bawei.erp.service.POrderService;
import com.bawei.erp.service.StockService;

@Service
public class POrderServiceImpl implements POrderService {

	@Resource
	private POrderMapper pOrderMapper;

	@Resource
	private StockService stockService;

	@Override
	public void addPOrder(POrder order) {
		pOrderMapper.insert(order);
	}

	@Override
	public void udpatePOrder(POrder order) {
		pOrderMapper.updateByPrimaryKeySelective(order);
	}

	@Override
	public void deletePOrder(Long id) {
		pOrderMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<POrder> getPOrder() {
		return pOrderMapper.selectByExample(null);
	}

	@Override
	public POrder getPOrderById(Long id) {
		return pOrderMapper.selectByPrimaryKey(id);
	}

	@Override
	public void purchaseStock(String sku, int count) {
		Stock stock = new Stock();
		stock.setSku(sku);
		stock.setPurchaseCount(count);
		stockService.updateStockBySKU(stock);
	}
}
